<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="layui/css/layui.css">
    <style type="text/css">
        #background {
            width: 100%;
            height: 100%;
            position: fixed;
            z-index: -1;
        }

        .container {
            width: 420px;
            height: 320px;
            min-height: 320px;
            max-height: 320px;
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            margin: auto;
            padding: 20px;
            z-index: 130;
            border-radius: 40px;
            background-color: rgba(255, 255, 255, 0.7);
            box-shadow: 0 3px 18px rgba(100, 0, 0, .5);
            font-size: 16px;
        }

        .layui-input {
            border-radius: 20px;
            width: 300px;
            height: 40px;
            font-size: 15px;
        }

        .layui-form-item {
            margin-left: -20px;
        }

        #logoid {
            margin-top: 10px;
            width: 300px;
            text-align: center;
            margin-left: 60px;
            font-size: 32px;
            color: #333;
            font-weight: 600;
            padding-bottom: 15px;
        }

        .layui-btn {
            margin-left: -50px;
            border-radius: 17px;
            width: 350px;
            height: 40px;
            font-size: 18px;
            background-color: #333;
            color: white;
            box-shadow: 0 3px 18px rgba(100, 0, 0, .5);
        }

        .font-set {
            font-size: 14px;
            text-decoration: none;
            margin-left: 120px;
        }

        a:hover {
            text-decoration: underline;
        }

        .xtname {
            margin-left: 50px;
            padding-top: 20px;
            color: white;
            width: 372px;
            font-size: 28px;
        }

        .error {
            color: red;
            display: none;
        }

        .error1 {
            color: red;
            display: none;
        }
    </style>
</head>
<body>
<img src="img/01.jpg" id="background">
<p class="xtname">基于区块链共享单车管理系统</p>
<div class="layui-form">
    <div class="container">
        <div class="layui-form-mid layui-word-aux">
            <p id="logoid">注&nbsp;&nbsp;册</p>
        </div>
        <input name="checkState" value="0" hidden="hidden">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="username" id="username" required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input" autofocus>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密 &nbsp;&nbsp;码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" id="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">身份</label>
            <div class="layui-input-block">
                <input type="text" id="roleId" name="roleId" itemid="roleId" placeholder="请输入您的身份" lay-verify="required" class="layui-input" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">确定</button>
                <button id="denglu" class="layui-btn" style=" margin-top: 10px; margin-left: -50px;">已有账号？去登录</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="layui/layui.js"></script>
<script type="text/javascript" src="js/public.js"></script>
<script>
    $("#denglu").click(function(){
        location.href="login.html"
    });

    layui.use(['form'], function(){
        var form = layui.form;
        // 监听提交
        form.on('submit(formDemo)', function(data){
            var geturl =url+user.register;
            var parm = data.field;
            var username=$("#username").val();
            var password=$("#password").val();
            var roleId=$("#roleId").val();
            //发起一个ajax请求
            $.ajax({
                type: "POST",
                url: geturl,
                contentType: 'application/json',
                data: JSON.stringify(parm),
                success: function (res) {
                    console.log(res)
                    if (res.data.state === "200") {
                        var storage = window.localStorage;
                        storage.setItem("username", username);
                        storage.setItem("password", password);
                        storage.setItem("roleId",roleId);
                        setTimeout(function () {
                            layer.msg('注册成功！');
                        }, 1000); // 延迟2秒跳转
                        setTimeout(function () {
                            location.href = "login.html";
                        }, 3000); // 延迟2秒跳转
                    } else if (res.data.state === "201") {
                        layer.msg("账号已存在！");
                    } else {
                        layer.msg('注册失败！');
                    }
                },
                beforeSend: function () {
                    $(".loading").css("display", "block");
                },
                complete: function () {
                    $(".loading").css("display", "none");
                },
            });

            return false; // 阻止表单跳转
        });
    });
</script>
</body>
</html>
